package com.firexxx.study.designmodel.sixconcept.requirement.addprocessstep;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 添加业务流程步骤类需求：从[满100 - 18吧]和打[打8折]中选择折扣最大的一种
 * 这种可以看作将新需求合并到了以前的变化点
 * @author: zhuangzhang2
 * @date: 2021-01-04 13:54
 */
public class Main {

    public static void main(String[] args) {
        int price = 60;
        //IPreferential preferential = new DiscountService();
        //IPreferential preferential = new ReduceService();
        /*
        //这里是修改流程的写法，修改流程的写法智慧更改业务流程，不会更改变化点
        int min = 0;
        List<IPreferential> preferentials = new ArrayList<>();
        preferentials.add(new DiscountService());
        preferentials.add(new ReduceService());
        for (IPreferential preferential : preferentials) {
            int result = preferential.preferential(price);
            if (min == 0) {
                min = result;
            } else if (min > result) {
                min = result;
            }
        }*/
        //修改点，调用方的逻辑通过代理模式封装在了MaxPreferentialService
        IPreferential preferential = new MaxPreferentialService();
        int discountedPrice = preferential.preferential(price);
        System.out.println("原始价格" + price + ",优惠后价格" + discountedPrice);
    }

}
